home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pct1-b.zip / INTRO2.DOC < prev    next >
Text File  |  1990-08-07  |  45KB  |  805 lines

  1.  
  2.  
  3.  
  4.                                                                              5
  5.  
  6.  
  7.              WHAT'S AN ASSEMBLER?
  8.  
  9.              What is the difference between a compiler and an assembler?
  10.  
  11.              A compiler is a program that takes the source code you have
  12.              written and turns it into machine language instructions that are
  13.              usable by the computer. A machine language instruction is a
  14.              binary number that tells the computer to do one specific thing.
  15.              This is something very specific like: add 1 to a specific
  16.              variable. The compiler does this in two steps. First, the
  17.              compiler takes each line of source code and turns the expression
  18.              on the line into a number of simple tasks to accomplish what is
  19.              desired, generating a number of assembler TEXT instructions and
  20.              data definitions. When the compiler is through with the source
  21.              code, it then takes these TEXT instructions and assembles them to
  22.              form an object module. An object module is a file that can be
  23.              linked with other files to form a larger program. 
  24.  
  25.              Why two steps instead of one? There are several reasons. This
  26.              allows a compiler writer to write a first part for any language
  27.              like Pascal, C, BASIC, etc., and then use the same assembler
  28.              part. This saves development time in a company that has more than
  29.              one type of compiler. You can insert a new assembler part without
  30.              worrying about the text generation part, or you can insert a new
  31.              text generation part without worrying about the assembler part.
  32.              Secondly, though an assembler is not a simple program, the
  33.              compiler's text generator is even more complicated. Putting the
  34.              two together is like trying to juggle eight balls instead of four
  35.              balls.
  36.  
  37.              This leads to the most vital reason. Not only would a unified
  38.              text-generator/assembler be more error prone, it would be almost
  39.              impossible to debug. If you are getting an error due to one type
  40.              of Pascal instruction, is this because it is being misunderstood
  41.              by the compiler or because the compiler is giving it the wrong
  42.              machine codes? In the two part system, the compiler writer can
  43.              look at the intermediate text code and isolate the problem into
  44.              one of the two halves.
  45.  
  46.              An assembler is a program that takes a TEXT file where each line
  47.              corresponds to a specific machine instruction or type of data,
  48.              calculates the address in memory where each piece of data or
  49.              machine instruction will be, translates each instruction and
  50.              piece of data into machine readable form, and inserts the
  51.              addresses of data and labels into machine instructions where
  52.              appropriate.{1}
  53.  
  54.  
  55.  
  56.              ____________________
  57.  
  58.                 1. A label is just a name which marks a certain spot in the
  59.              assembler code.
  60.  
  61.              ______________________
  62.  
  63.              The PC Assembler Tutor - Copyright (C) 1990 Chuck Nelson
  64.  
  65.  
  66.  
  67.  
  68.              The PC Assembler Tutor                                          6
  69.              ______________________
  70.  
  71.              The text name for a machine instruction is called a mnemonic.{2}
  72.              It indicates what is being done by the instruction. Which would
  73.              you rather use for multiplication, 'MUL' or '11110111xx100xxx'?
  74.              These 'x's indicate a digit whose value depends on where
  75.              something is in memory. For each mnemonic there is a single
  76.              machine instruction which performs the operation. 
  77.  
  78.              This means that the assembler's task is relatively simple. It
  79.              only needs to allocate space for all the variables and
  80.              instructions, to translate each mnemonic and data value into its
  81.              corresponding machine code, and finally put it into a machine
  82.              usable file. 
  83.  
  84.              Here you need to know what different forms of file there are. 
  85.  
  86.                  1) An executable (.EXE) file contains certain information
  87.                  for the operating system when the program is started. This
  88.                  allows the program to be as large as is wanted.
  89.  
  90.                  2) A .COM file contains no information for the operating
  91.                  system. When the operating system starts a .COM file it
  92.                  simply puts it in memory and starts it. Files with a .COM
  93.                  extension are limited to a length of 64k bytes. 
  94.  
  95.                  3) Binary files are files which must be loaded into a .COM
  96.                  or .EXE program before being run. They cannot be used by
  97.                  themselves. They are archaic. They are a crutch for those
  98.                  compilers which don't support .OBJ files, and are
  99.                  disappearing.
  100.  
  101.                  4) An object (.OBJ) file is a section of a program. It
  102.                  contains code and variables, but also contains information
  103.                  that can be used to combine it with other object files into
  104.                  a larger program. A linker can convert one or more object
  105.                  files into an executable file.
  106.  
  107.  
  108.              Things have moved along in the past few years. TurboPascal 3.0
  109.              generated .COM files. This wasn't because .COM files were
  110.              superior but because it was too difficult to generate the extra
  111.              information needed to produce an .OBJ file. Interpreted BASIC
  112.              required binary files because it did not have the ability to use
  113.              .OBJ files. The situation now is:
  114.  
  115.                  If you want to link with the current Turbo Pascal, you
  116.                  should use an .OBJ file. If you want to link with QuickC,
  117.                  you need an .OBJ file. If you want to combine an external
  118.                  subprogram with QuickBASIC, you need an .OBJ file. Get the
  119.                  picture?
  120.  
  121.              No assembler makes .EXE files. If you have a single file that you
  122.              want made onto a stand alone .EXE file, you first make an .OBJ
  123.              file and then use that single file with LINK. 
  124.  
  125.              ____________________
  126.  
  127.                 2. You don't pronounce that first 'm'.
  128.  
  129.  
  130.  
  131.  
  132.              Introduction                                                    7
  133.              ____________
  134.  
  135.              When making a .COM file, the normal route is to make .OBJ files,
  136.              link them together into an EXE file, and then convert them to a
  137.              .COM file with a program called EXE2BIN. This allows you to
  138.              divide the problem into a number of subproblems and put them all
  139.              together at the end.
  140.  
  141.              As you can see from the above, the job for the assembler is to
  142.              take a text file and convert it into an .OBJ file. The three
  143.              assemblers that you are most likely to have are MASM, A86, and
  144.              TurboAssembler. They all produce object files. Since assemblers
  145.              simply supply the machine code for each instruction, they will
  146.              all produce the exact same code.{3}
  147.  
  148.              This is one of the differences between assemblers and compilers.
  149.              The text generation phase of the compiler requires creativity. It
  150.              is the compiler writer's idea of how to solve a certain problem
  151.              in a specific language. This generated text is copyrighted, and
  152.              you need a license to distribute a program that includes this
  153.              generated text. An assembler. on the other hand, is just a
  154.              drudge. If you had a book with the machine codes and had enough
  155.              time, you could produce the same file byte for byte that the
  156.              assembler would produce for a .COM file. There is no creativity
  157.              involved in the generated code, and there is no license involved
  158.              in its distribution. 
  159.  
  160.              There is some difference in the speed of those three assemblers,
  161.              but I'll have a comment about that after I give you the numbers.
  162.              These numbers are from the time of hitting the ENTER key to the
  163.              return of the DOS prompt ('>'). These are on a low speed machine
  164.              so your numbers should be better, but won't be any worse.
  165.  
  166.                                           A86       TurboASM       MASM
  167.  
  168.                  one page of code         3.2          8.8         10.3
  169.                  20 pages of code         7.3         12.7         20.4
  170.                  60 pages of code        12.5         22.9         43.3
  171.  
  172.              All these numbers are in seconds. A86 is the fastest. It loads
  173.              faster because it itself is a .COM file, and it works faster. But
  174.              even the slowest (MASM), is fast enough. How long does it take to
  175.              write 60 pages of code? Probably a week or two. Writing assembler
  176.              code is normally slower than writing code for a high-level
  177.              language. Even the slowest finishes the assembly in well under a
  178.              minute. Think of the time it would take to compile 60 pages of
  179.              Pascal code. 
  180.  
  181.              In fact, the normal length of a file will be from 10 to 20 pages,
  182.              so these are the numbers you need to think of. These will be the
  183.              smaller .OBJ files which are linked together by the linker. 
  184.  
  185.              If you have one of these assemblers you don't need anything
  186.              different. If you need to get one, you can use this information
  187.              ____________________
  188.  
  189.                 3. Or functionally the same code. Sometimes there are two
  190.              different instructions that do the same thing, just as 6+1, 5+2
  191.              and 4+3 all produce 7.
  192.  
  193.  
  194.  
  195.  
  196.              The PC Assembler Tutor                                          8
  197.              ______________________
  198.  
  199.              to help you in your selection. The following prices are as of
  200.              mid-1990.
  201.  
  202.              A86 is available through shareware. It costs $50.00 for the
  203.              assembler alone, $80.00 with the debugger. Add another $10.00 if
  204.              you want a printed manual.
  205.  
  206.              Both MASM and Turbo Assembler come with assembler, debugger, a
  207.              number of utility programs and several manuals. They both retail
  208.              for $150.00, but even a quick glance at BYTE magazine will find
  209.              you a place that is selling them for $105.00 - $110.00. They come
  210.              bundled, so you cannot buy the assembler without the debugger
  211.              (The Microsoft debugger is Codeview and the Borland debugger is
  212.              Turbo Debugger).
  213.  
  214.              Speaking of debuggers, you may be thinking, "Well, I have DEBUG,
  215.              so why do I want another debugger?" DEBUG has been outdated for
  216.              several years now. It has been supplanted by symbolic debuggers
  217.              which associate code with specific lines in the original text
  218.              file. You give the symbolic debugger the .EXE file along with the
  219.              text files that produced it, and it shows you your source code as
  220.              you go along. Here's a section of code we will meet later in the
  221.              Tutor:
  222.  
  223.                  ; - - - - - - - - - - - - - - - - - - - -
  224.                  start: push  ds               ; set up for return 
  225.                       sub   ax,ax 
  226.                       push  ax 
  227.                       mov   ax, DATASTUFF    ; load ds 
  228.                       mov   ds,ax 
  229.  
  230.                  outer_loop: 
  231.                       lea  ax, multiplicand    ; load multiplicand 
  232.                       call get_unsigned_8byte 
  233.                       call print_unsigned_8byte 
  234.                       call get_unsigned        ; unsigned word to multiplier 
  235.                       mov  multiplier, ax 
  236.                   
  237.                       lea  si, multiplicand    ; load pointers 
  238.                       lea  bx, result 
  239.                  ; - - - - - - - - - - - - - - - - - - - -
  240.  
  241.              Don't worry about what these instructions do. You'll learn that
  242.              later. Here is DEBUG's idea of what is going on:
  243.  
  244.              ******************** DEBUG SCREEN SHOT ************************
  245.              -r 
  246.              AX=0000 BX=0000 CX=2749 DX=0000 SP=0A00 BP=0000 SI=0000 DI=0000 
  247.              DS=0D7E ES=0D7E SS=0D8E CS=0E7F  NV UP DI PL NZ NA PO NC 
  248.              0E7F:0000 1E            PUSH    DS 
  249.              -u0E7F:0000 2A 
  250.              0E7F:0000 1E            PUSH    DS 
  251.              0E7F:0001 2BC0          SUB     AX,AX 
  252.              0E7F:0003 50            PUSH    AX 
  253.              0E7F:0004 B82E0E        MOV     AX,0E2E 
  254.              0E7F:0007 8ED8          MOV     DS,AX 
  255.              0E7F:0009 8D060800      LEA     AX,[0008] 
  256.  
  257.  
  258.  
  259.  
  260.              Introduction                                                    9
  261.              ____________
  262.  
  263.              0E7F:000D E80C14        CALL    141C 
  264.              0E7F:0010 E84B11        CALL    115E 
  265.              0E7F:0013 E8F505        CALL    060B 
  266.              0E7F:0016 A31000        MOV     [0010],AX 
  267.              0E7F:0019 8D360800      LEA     SI,[0008] 
  268.              0E7F:001D 8D1E1200      LEA     BX,[0012] 
  269.              ********************** END DEBUG *******************************
  270.  
  271.              Part of this is understandable, but a lot of it is confusing, and
  272.              you have lost the concept of what you are trying to do. To see
  273.              what a symbolic debugger does with the same code, here is the
  274.              Turbo Debugger's idea of what is happening:
  275.  
  276.  
  277.  
  278.  ************************* TURBO SCREEN SHOT {4} *****************************
  279.    File   View   Run   Breakpoints   Data   Window   Options             READY
  280.  .Module: debugtst  File: debugtst.asm 74....................................1.
  281.  .                                                                            .
  282.  .  start: push  ds               ; set up for return      .Registers......3. .
  283.  .         sub   ax,ax                                     .  ax 5C94   .c=0. .
  284.  .         push  ax                                        .  bx 0000   .z=1. .
  285.  .                                                         .  cx 0000   .s=0. .
  286.  .         mov   ax, DATASTUFF    ; load ds                .  dx 0000   .o=0. .
  287.  .         mov   ds,ax                                     .  si 0000   .p=1. .
  288.  .                                                         .  di 0000   .a=0. .
  289.  .  outer_loop:                                            .  bp 0000   .i=1. .
  290.  .          lea     ax, multiplicand        ; load multipli.  sp 09FA   .d=0. .
  291.  .          call    get_unsigned_8byte                     .  ds 4AD6   .   . .
  292.  .          call    print_unsigned_8byte                   .  es 4A26   .   . .
  293.  .          call    get_unsigned            ; unsigned word.  ss 4A36   .   . .
  294.  .          mov     multiplier, ax                         .  cs 4B27   .   . .
  295.  .                                                         .  ip 0019   .   . .
  296.  .                                                         .................. .
  297.  .          lea     si, multiplicand        ; load pointers                   .
  298.  ..............................................................................
  299.  .Watches....................................................................2.
  300.  .multiplier,d                  23700                                         .
  301.  .multiplicand                  qword 00000042E843515D                        .
  302.  ..............................................................................
  303.   F1-Help F2-Bkpt F3-Close F4-Here F5-Zoom F6-Next F7-Trace F8-Step F9-Run
  304.  *****************************************************************************
  305.  
  306.  
  307.  
  308.              DEBUG really doesn't meet our needs. Of course, those of you who
  309.              still use EDLIN to write 20 page documents should feel free to
  310.              use DEBUG.
  311.  
  312.              Modern language compilers have their own debuggers in their
  313.              environments, so we only need a debugger for the assembler. Turbo
  314.              Debugger and Code View do the job very well. D86 is better than
  315.              DEBUG but it has some problems.
  316.              ____________________
  317.  
  318.                 4. Turbo Debugger is (C) Copyright 1988-1989 Borland
  319.              International.
  320.  
  321.  
  322.  
  323.  
  324.              The PC Assembler Tutor                                         10
  325.              ______________________
  326.  
  327.  
  328.              If you actually want a debugger that will symbolically debug
  329.              everything that supports symbolic debugging, you might want to
  330.              take a look at the Turbo Debugger. It has more power than you are
  331.              ever likely to need. 
  332.  
  333.              "The Assembler Helper", the program which comes with the Tutor,
  334.              is NOT a debugger. Debuggers are designed to show you what is
  335.              happening with your code; the Helper is designed to show you what
  336.              is happening with the 8086. It's a fundamental difference in
  337.              outlook. 
  338.  
  339.              If you want to use a debugger while you are doing this tutorial
  340.              it is possible but the results are not guaranteed. Please see
  341.              DEBUGGER.DOC in \COMMENTS for some information about the
  342.              different debuggers and how to use ASMHELP with a debugger. You
  343.              should not try to do this before you are in chapter 5 or 6.
  344.  
  345.              You may have noticed that CHASM, an assembler distributed through
  346.              shareware, was not listed. There is a reason for this. It can't
  347.              produce .OBJ files, so it cannot produce the standard files for
  348.              use with current compilers, including QuickBASIC.  CHASM is also
  349.              unusable with this tutorial because it cannot produce files to
  350.              link with ASMHELP.OBJ, the i/o interface program. If you are
  351.              getting a shareware assembler, get A86. It's a quality assembler.
  352.  
  353.              This tutorial was originally written for those using MASM. In
  354.              order to allow those using the Turbo Assembler and A86 to follow
  355.              along, there is a document for each one in \COMMENTS which
  356.              explains any differences between what is in the chapters (which
  357.              use MASM as an example) and what the respective assemblers do.
  358.              There aren't that many differences. The pathnames are
  359.              \COMMENTS\TURBO.DOC and \COMMENTS\A86.DOC.
  360.  
  361.  
  362.  
  363.  
  364.  
  365.                                                                              1
  366.  
  367.                                    TABLE OF CONTENTS
  368.  
  369.  
  370.              Chapter 0.1 - Numbers And Arithmetic  . . . . . . . . . . .  i
  371.                  Base 10 Machine . . . . . . . . . . . . . . . . . . . .  i
  372.                  Negative Numbers  . . . . . . . . . . . . . . . . . . . ii
  373.                  10's Complement . . . . . . . . . . . . . . . . . . .  iii
  374.                  Addition  . . . . . . . . . . . . . . . . . . . . . . .  v
  375.                  Subtraction . . . . . . . . . . . . . . . . . . . . . .  v
  376.                  Modular Math  . . . . . . . . . . . . . . . . . . . . . vi
  377.                  Sign Extension  . . . . . . . . . . . . . . . . . . . . ix
  378.                  Overflow  . . . . . . . . . . . . . . . . . . . . . .  xii
  379.                  Multiplication  . . . . . . . . . . . . . . . . . . . xiii
  380.                  Division  . . . . . . . . . . . . . . . . . . . . . .  xiv
  381.  
  382.              Chapter 0.2 - Bases 2 And 16  . . . . . . . . . . . . . . . xv
  383.                  Base Conversion . . . . . . . . . . . . . . . . . . . . xv
  384.                  Binary Math . . . . . . . . . . . . . . . . . . . . .  xvi
  385.                  2's Complement  . . . . . . . . . . . . . . . . . . . xvii
  386.                  Sign Extension  . . . . . . . . . . . . . . . . . .  xviii
  387.  
  388.              Chapter 0.3 - Logic . . . . . . . . . . . . . . . . . . .  xxi
  389.                  AND . . . . . . . . . . . . . . . . . . . . . . . . .  xxi
  390.                  OR  . . . . . . . . . . . . . . . . . . . . . . . . . xxii
  391.                  XOR . . . . . . . . . . . . . . . . . . . . . . . . . xxii
  392.                  NOT . . . . . . . . . . . . . . . . . . . . . . . .  xxiii
  393.  
  394.              Chapter 0.4 - Memory  . . . . . . . . . . . . . . . . . .  xxv
  395.                  Segmentation  . . . . . . . . . . . . . . . . . . . .  xxv
  396.                  Numbers In Memory . . . . . . . . . . . . . . . . .  xxvii
  397.  
  398.              Chapter 0.5 - Style . . . . . . . . . . . . . . . . . . . xxix
  399.  
  400.  
  401.  
  402.              Chapter 1 - Some Simple Programs  . . . . . . . . . . . . .  1
  403.                  Label . . . . . . . . . . . . . . . . . . . . . . . . .  3
  404.                  CALL  . . . . . . . . . . . . . . . . . . . . . . . . .  3
  405.                  JMP . . . . . . . . . . . . . . . . . . . . . . . . . .  3
  406.  
  407.              Chapter 2 - Data  . . . . . . . . . . . . . . . . . . . . . 11
  408.                  DB, DW, DD, DQ, DT, DF  . . . . . . . . . . . . . . . . 11
  409.                  Definition of Constants . . . . . . . . . . . . . . . . 13
  410.  
  411.              Chapter 3 - Asmhelp . . . . . . . . . . . . . . . . . . . . 16
  412.                  Registers . . . . . . . . . . . . . . . . . . . . . . . 16
  413.                  Show_regs . . . . . . . . . . . . . . . . . . . . . . . 17
  414.                  MOV . . . . . . . . . . . . . . . . . . . . . . . . . . 19
  415.  
  416.              Chapter 4 - Show_regs . . . . . . . . . . . . . . . . . . . 24
  417.                  Show_reg Codes  . . . . . . . . . . . . . . . . . . . . 29
  418.  
  419.              Chapter 5 - Addition and Subtraction  . . . . . . . . . . . 31
  420.                  LOOP  . . . . . . . . . . . . . . . . . . . . . . . . . 31
  421.  
  422.              ______________________
  423.  
  424.              The PC Assembler Tutor - Copyright (C) 1990 Chuck Nelson
  425.  
  426.  
  427.  
  428.  
  429.              The PC Assembler Tutor                                          2
  430.              ______________________
  431.  
  432.                  OF, ZF, SF, CF  . . . . . . . . . . . . . . . . . . . . 32
  433.                  ADD . . . . . . . . . . . . . . . . . . . . . . . . . . 33
  434.                  PUSH  . . . . . . . . . . . . . . . . . . . . . . . . . 33
  435.                  POP . . . . . . . . . . . . . . . . . . . . . . . . . . 34
  436.                  SUB . . . . . . . . . . . . . . . . . . . . . . . . . . 37
  437.                  JC, JNC, JO, JNO  . . . . . . . . . . . . . . . . . . . 38
  438.                  INTO  . . . . . . . . . . . . . . . . . . . . . . . . . 39
  439.                  INTO.COM  . . . . . . . . . . . . . . . . . . . . . . . 39
  440.  
  441.              Chapter 6 - Multiplication and Division . . . . . . . . . . 41
  442.                  MUL . . . . . . . . . . . . . . . . . . . . . . . . . . 41
  443.                  IMUL  . . . . . . . . . . . . . . . . . . . . . . . . . 41
  444.                  DIV . . . . . . . . . . . . . . . . . . . . . . . . . . 44
  445.                  IDIV  . . . . . . . . . . . . . . . . . . . . . . . . . 44
  446.  
  447.              Chapter 7 - Logic . . . . . . . . . . . . . . . . . . . . . 47
  448.                  AND . . . . . . . . . . . . . . . . . . . . . . . . . . 47
  449.                  TEST  . . . . . . . . . . . . . . . . . . . . . . . . . 49
  450.                  OR  . . . . . . . . . . . . . . . . . . . . . . . . . . 50
  451.                  XOR . . . . . . . . . . . . . . . . . . . . . . . . . . 50
  452.                  NEG . . . . . . . . . . . . . . . . . . . . . . . . . . 51
  453.                  NOT . . . . . . . . . . . . . . . . . . . . . . . . . . 51
  454.                  Masks . . . . . . . . . . . . . . . . . . . . . . . . . 52
  455.  
  456.              Chapter 8 - Shift and Rotate  . . . . . . . . . . . . . . . 56
  457.                  SAL, SHL  . . . . . . . . . . . . . . . . . . . . . . . 56
  458.                  INC, DEC  . . . . . . . . . . . . . . . . . . . . . . . 57
  459.                  SHR . . . . . . . . . . . . . . . . . . . . . . . . . . 58
  460.                  SAR . . . . . . . . . . . . . . . . . . . . . . . . . . 59
  461.                  ROL, ROR  . . . . . . . . . . . . . . . . . . . . . . . 60
  462.                  RCL, RCR  . . . . . . . . . . . . . . . . . . . . . . . 61
  463.  
  464.              Chapter 9 - Jumps . . . . . . . . . . . . . . . . . . . . . 68
  465.                  CMP . . . . . . . . . . . . . . . . . . . . . . . . . . 68
  466.                  Signed and Unsigned Conditional Jumps . . . . . . . . . 70
  467.                  Flag Conditional Jumps  . . . . . . . . . . . . . . . . 75
  468.                  JCXZ  . . . . . . . . . . . . . . . . . . . . . . . . . 75
  469.  
  470.              Chapter 10 - Templates  . . . . . . . . . . . . . . . . . . 78
  471.                  .LST File . . . . . . . . . . . . . . . . . . . . . . . 78
  472.                  SEGMENTS  . . . . . . . . . . . . . . . . . . . . . . . 84
  473.                  PUBLIC (SEGMENTS) . . . . . . . . . . . . . . . . . . . 85
  474.                  CLASS . . . . . . . . . . . . . . . . . . . . . . . . 85ff
  475.                  ENDS  . . . . . . . . . . . . . . . . . . . . . . . . . 92
  476.                  ASSUME  . . . . . . . . . . . . . . . . . . . . . . . . 93
  477.                  Segment Overrides . . . . . . . . . . . . . . . . . . . 93
  478.                  Subroutines . . . . . . . . . . . . . . . . . . . . . . 96
  479.                  END . . . . . . . . . . . . . . . . . . . . . . . . . . 97
  480.                  RET . . . . . . . . . . . . . . . . . . . . . . . . . . 98
  481.                  EXTRN . . . . . . . . . . . . . . . . . . . . . . . . . 99
  482.                  STACK . . . . . . . . . . . . . . . . . . . . . . . .  101
  483.  
  484.              Chapter 11 - Addressing Modes . . . . . . . . . . . . . .  104
  485.                  EQU . . . . . . . . . . . . . . . . . . . . . . . . .  110
  486.                  All Addressing Modes  . . . . . . . . . . . . . . . .  114
  487.                  OFFSET  . . . . . . . . . . . . . . . . . . . . . . .  118
  488.                  SEG . . . . . . . . . . . . . . . . . . . . . . . . .  118
  489.  
  490.  
  491.  
  492.  
  493.              Table Of Contents                                               3
  494.              _________________
  495.  
  496.                  LEA . . . . . . . . . . . . . . . . . . . . . . . . .  118
  497.  
  498.              Chapter 12 - Multiple Word Arithmetic I . . . . . . . . .  122
  499.                  ADC . . . . . . . . . . . . . . . . . . . . . . . . .  123
  500.                  CLC . . . . . . . . . . . . . . . . . . . . . . . . .  124
  501.                  SBB . . . . . . . . . . . . . . . . . . . . . . . . .  126
  502.  
  503.              Chapter 13 - Multiple Word Arithmetic II  . . . . . . . .  129
  504.                  Unsigned Multiplication . . . . . . . . . . . . . . .  129
  505.                  Unsigned Division . . . . . . . . . . . . . . . . . .  130
  506.  
  507.              Chapter 14 - Zoom . . . . . . . . . . . . . . . . . . . .  134
  508.  
  509.              Chapter 15 - Subroutines  . . . . . . . . . . . . . . . .  137
  510.                  PUSHREGS.MAC  . . . . . . . . . . . . . . . . . . . .  137
  511.                  EXTRN in Subroutines  . . . . . . . . . . . . . . . .  142
  512.                  Passing Data  . . . . . . . . . . . . . . . . . . . .  144
  513.                  Near and Far Procedures . . . . . . . . . . . . . . .  145
  514.                  The Stack . . . . . . . . . . . . . . . . . . . . . .  148
  515.                  Types of Returns  . . . . . . . . . . . . . . . . . .  153
  516.                  PUSHREGS  . . . . . . . . . . . . . . . . . . . . . .  154
  517.                  POPREGS . . . . . . . . . . . . . . . . . . . . . . .  154
  518.                  LDS . . . . . . . . . . . . . . . . . . . . . . . . .  157
  519.                  LES . . . . . . . . . . . . . . . . . . . . . . . . .  157
  520.                  Towers of Hanoi . . . . . . . . . . . . . . . . . . .  162
  521.                  Summary . . . . . . . . . . . . . . . . . . . . . . .  166
  522.  
  523.              Chapter 16 - Long Signed Multiplication And Division  . .  170
  524.                  Long Negation . . . . . . . . . . . . . . . . . . . .  170
  525.  
  526.              Chapter 17 - Interrupts . . . . . . . . . . . . . . . . .  177
  527.                  INT . . . . . . . . . . . . . . . . . . . . . . . . .  177
  528.                  NMI . . . . . . . . . . . . . . . . . . . . . . . . .  181
  529.                  IEF . . . . . . . . . . . . . . . . . . . . . . . . .  181
  530.                  STI . . . . . . . . . . . . . . . . . . . . . . . . .  181
  531.                  CLI . . . . . . . . . . . . . . . . . . . . . . . . .  181
  532.                  INT 3 . . . . . . . . . . . . . . . . . . . . . . . .  182
  533.  
  534.              Chapter 18 - Ports  . . . . . . . . . . . . . . . . . . .  185
  535.                  IN  . . . . . . . . . . . . . . . . . . . . . . . . .  185
  536.                  OUT . . . . . . . . . . . . . . . . . . . . . . . . .  186
  537.                  Parity  . . . . . . . . . . . . . . . . . . . . . . .  186
  538.  
  539.              Chapter 19 - Strings  . . . . . . . . . . . . . . . . . .  191
  540.                  SCAS  . . . . . . . . . . . . . . . . . . . . . . . .  191
  541.                  DF  . . . . . . . . . . . . . . . . . . . . . . . . .  191
  542.                  REP/REPE/REPNE  . . . . . . . . . . . . . . . . . . .  195
  543.                  STOS  . . . . . . . . . . . . . . . . . . . . . . . .  196
  544.                  LODS  . . . . . . . . . . . . . . . . . . . . . . . .  198
  545.                  MOVS  . . . . . . . . . . . . . . . . . . . . . . . .  199
  546.                  CMPS  . . . . . . . . . . . . . . . . . . . . . . . .  204
  547.                  Segment Overrides . . . . . . . . . . . . . . . . . .  207
  548.                  REP and Overrides . . . . . . . . . . . . . . . . . .  209
  549.  
  550.              Chapter 20 - Control Structures . . . . . . . . . . . . .  212
  551.                  IF  . . . . . . . . . . . . . . . . . . . . . . . . .  212
  552.                  WHILE . . . . . . . . . . . . . . . . . . . . . . . .  214
  553.  
  554.  
  555.  
  556.  
  557.              The PC Assembler Tutor                                          4
  558.              ______________________
  559.  
  560.                  DO-WHILE  . . . . . . . . . . . . . . . . . . . . . .  215
  561.                  BREAK . . . . . . . . . . . . . . . . . . . . . . . .  215
  562.                  CONTINUE  . . . . . . . . . . . . . . . . . . . . . .  215
  563.                  FOR . . . . . . . . . . . . . . . . . . . . . . . . .  216
  564.                  SWITCH  . . . . . . . . . . . . . . . . . . . . . . .  217
  565.  
  566.              Chapter 21 - .COM Files . . . . . . . . . . . . . . . . .  219
  567.                  .COM Template . . . . . . . . . . . . . . . . . . . .  219
  568.                  PSP . . . . . . . . . . . . . . . . . . . . . . . . .  220
  569.                  ASSUME  . . . . . . . . . . . . . . . . . . . . . . .  221
  570.                  Phase Errors  . . . . . . . . . . . . . . . . . . . .  221
  571.  
  572.              Chapter 22 - BCD Numbers  . . . . . . . . . . . . . . . .  229
  573.                  Unpacked BCD  . . . . . . . . . . . . . . . . . . . .  229
  574.                  Packed BCD  . . . . . . . . . . . . . . . . . . . . .  230
  575.                  DAA . . . . . . . . . . . . . . . . . . . . . . . . .  232
  576.                  DAS . . . . . . . . . . . . . . . . . . . . . . . . .  233
  577.                  AAA . . . . . . . . . . . . . . . . . . . . . . . . .  240
  578.                  AAS . . . . . . . . . . . . . . . . . . . . . . . . .  242
  579.                  AAM . . . . . . . . . . . . . . . . . . . . . . . . .  242
  580.                  AAD . . . . . . . . . . . . . . . . . . . . . . . . .  243
  581.                  Unpacking . . . . . . . . . . . . . . . . . . . . . .  245
  582.                  Packing . . . . . . . . . . . . . . . . . . . . . . .  246
  583.  
  584.              Chapter 23 - XLAT . . . . . . . . . . . . . . . . . . . .  253
  585.                  EBCDIC Numbers  . . . . . . . . . . . . . . . . . . .  253
  586.                  XLAT  . . . . . . . . . . . . . . . . . . . . . . . .  253
  587.                  Translation Table . . . . . . . . . . . . . . . . . .  253
  588.  
  589.              Chapter 24 - Miscellaneous Instructions . . . . . . . . .  264
  590.                  XCHG  . . . . . . . . . . . . . . . . . . . . . . . .  264
  591.                  ESC . . . . . . . . . . . . . . . . . . . . . . . . .  264
  592.                  WAIT  . . . . . . . . . . . . . . . . . . . . . . . .  264
  593.                  FWAIT . . . . . . . . . . . . . . . . . . . . . . . .  264
  594.                  LOCK  . . . . . . . . . . . . . . . . . . . . . . . .  265
  595.                  LOOPE/LOOPNE  . . . . . . . . . . . . . . . . . . . .  265
  596.                  HALT  . . . . . . . . . . . . . . . . . . . . . . . .  266
  597.                  CMC . . . . . . . . . . . . . . . . . . . . . . . . .  266
  598.                  LAHF  . . . . . . . . . . . . . . . . . . . . . . . .  266
  599.                  SAHF  . . . . . . . . . . . . . . . . . . . . . . . .  267
  600.                  NOP . . . . . . . . . . . . . . . . . . . . . . . . .  267
  601.  
  602.              Chapter 25 - What Does It All Mean? . . . . . . . . . . .  268
  603.                  Interrupts  . . . . . . . . . . . . . . . . . . . . .  269
  604.                  Data Bus  . . . . . . . . . . . . . . . . . . . . . .  273
  605.                  Alignment Type  . . . . . . . . . . . . . . . . . . .  274
  606.  
  607.              Chapter 26 - Simplifying The Template . . . . . . . . . .  276
  608.                  INT 21h Function 4Ch  . . . . . . . . . . . . . . . .  276
  609.                  Exit Code . . . . . . . . . . . . . . . . . . . . . .  276
  610.                  Standardized Segments . . . . . . . . . . . . . . . .  277
  611.                  _DATA . . . . . . . . . . . . . . . . . . . . . . . .  279
  612.                  _BSS  . . . . . . . . . . . . . . . . . . . . . . . .  279
  613.                  CONST . . . . . . . . . . . . . . . . . . . . . . . .  280
  614.                  Literals  . . . . . . . . . . . . . . . . . . . . . .  280
  615.                  STACK . . . . . . . . . . . . . . . . . . . . . . . .  280
  616.                  Groups  . . . . . . . . . . . . . . . . . . . . . . .  280
  617.  
  618.  
  619.  
  620.  
  621.              Table Of Contents                                               5
  622.              _________________
  623.  
  624.                  DGROUP  . . . . . . . . . . . . . . . . . . . . . . .  281
  625.                  Groups and OFFSET . . . . . . . . . . . . . . . . . .  284
  626.                  Standardized Segment Names  . . . . . . . . . . . . .  287
  627.                  Standardized Segment Directives . . . . . . . . . . .  288
  628.                  .MODEL Names  . . . . . . . . . . . . . . . . . . . .  291
  629.                  Summary . . . . . . . . . . . . . . . . . . . . . . .  293
  630.  
  631.              APPENDIX
  632.  
  633.              Appendix I - The PC Assembler Helper  . . . . . . . . . . .  i
  634.              Appendix II - The 8086 Instruction Set  . . . . . . . . . xiii
  635.              Appendix III - Instruction Speed And Flags  . . . . . .  xxvii
  636.  
  637.              ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  638.  
  639.                                 ANCILLARY MATERIAL
  640.  
  641.  
  642.              DEBUGGERS (DEBUGGER.DOC)
  643.              TASM (TASM.DOC)
  644.              A86 (A86.DOC)
  645.  
  646.  
  647.  
  648.              BASIC (BASIC1.DOC, BASIC2-1.DOC, BASIC2-2.DOC)
  649.              Using Basic . . . . . . . . . . . . . . . . . . . . . . .  mmi
  650.                  Variable Typing . . . . . . . . . . . . . . . . . . .  mmi
  651.                  Default Type  . . . . . . . . . . . . . . . . . . . . mmii
  652.  
  653.              Interfacing Basic With Assembler  . . . . . . . . . . .  mmvii
  654.                  Memory Allocation . . . . . . . . . . . . . . . . .  mmvii
  655.                  String Allocation . . . . . . . . . . . . . . . . . mmviii
  656.                  Data Output . . . . . . . . . . . . . . . . . . . . .  mmx
  657.                  FIELD . . . . . . . . . . . . . . . . . . . . . . .  mmxii
  658.                  LSET/MID$/RSET  . . . . . . . . . . . . . . . . . . mmxiii
  659.                  MKI$, MKL$, MKS$, MKD$  . . . . . . . . . . . . . . mmxiii
  660.                  CVI, CVL, CVS, CVD  . . . . . . . . . . . . . . . . mmxiii
  661.                  STR$, VAL . . . . . . . . . . . . . . . . . . . . .  mmxiv
  662.                  VARPTR  . . . . . . . . . . . . . . . . . . . . . .  mmxvi
  663.                  PTR86 (Basic 3.0) . . . . . . . . . . . . . . . . . mmxvii
  664.                  BUILDLIB.EXE  . . . . . . . . . . . . . . . . . . . mmxvii
  665.                  VARSEG (Basic 4.0)  . . . . . . . . . . . . . . .  mmxviii
  666.                  Basic Calling Conventions . . . . . . . . . . . . .  mmxix
  667.                  INT86 . . . . . . . . . . . . . . . . . . . . . .  mxxviii
  668.                  SADD  . . . . . . . . . . . . . . . . . . . . . . . mmxxix
  669.                  BLOAD . . . . . . . . . . . . . . . . . . . . . . .  mmxxx
  670.                  Summary . . . . . . . . . . . . . . . . . . . . . . mmxxxi
  671.                  Interfacing Basic With Assembler  . . . . . . . . .  mmvii
  672.  
  673.  
  674.              Ancillary Programs (MISHMASH.DOC)
  675.                  General Block Move  . . . . . . . . . . . . . . . . . .  1
  676.                  Block Multiplication  . . . . . . . . . . . . . . . . .  3
  677.                  Binary Multiplication . . . . . . . . . . . . . . . . .  6
  678.                  Binary Division . . . . . . . . . . . . . . . . . . . .  9
  679.  
  680.  
  681.  
  682.  
  683.  
  684.                                                                           294
  685.  
  686.                                           INDEX
  687.  
  688.  
  689.            AAA . . . . . . . . . . . .240      Far Procedures. . . . . . .145 
  690.            AAD . . . . . . . . . . . .243      Flag Conditional Jumps. . . 75 
  691.            AAM . . . . . . . . . . . .242      FOR . . . . . . . . . . . .216 
  692.            AAS . . . . . . . . . . . .242      FWAIT . . . . . . . . . . .264 
  693.            ADC . . . . . . . . . . . .123 
  694.            ADD . . . . . . . . . . . . 33      Groups. . . . . . . . . . .280 
  695.            Addition. . . . . . . . . . .v      Groups and OFFSET . . . . .284 
  696.            Addressing Modes. . . . . .114 
  697.            Alignment Type. . . . . . .274      HALT. . . . . . . . . . . .266 
  698.            AND . . . . . . . . . .xxi, 47 
  699.            ASSUME. . . . . . . . .93, 221      IDIV. . . . . . . . . . . . 44 
  700.                                                IEF . . . . . . . . . . . .181 
  701.            Base 10 Machine . . . . . . .i      IF. . . . . . . . . . . . .212 
  702.            Base Conversion . . . . . . xv      IMUL. . . . . . . . . . . . 41 
  703.            Binary Math . . . . . . . .xvi      IN. . . . . . . . . . . . .185 
  704.            BREAK . . . . . . . . . . .215      INC . . . . . . . . . . . . 57 
  705.            _BSS. . . . . . . . . . . .279      INT . . . . . . . . . . . .177 
  706.                                                INT 21h Function 4h . . . .276 
  707.            CALL. . . . . . . . . . . . .3      INT 3 . . . . . . . . . . .182 
  708.            CF. . . . . . . . . . . . . 32      Interrupts. . . . . . . . .269 
  709.            CLASS . . . . . . . . . . 85ff      INTO. . . . . . . . . . . . 39 
  710.            CLC . . . . . . . . . . . .124      INTO.COM. . . . . . . . . . 39 
  711.            CLI . . . . . . . . . . . .181 
  712.            CMC . . . . . . . . . . . .266      JUMPS . . . . . . . . . . . 70 
  713.            CMP . . . . . . . . . . . . 68      JC, JNC . . . . . . . . . . 38 
  714.            CMPS. . . . . . . . . . . .204      JCXZ. . . . . . . . . . . . 75 
  715.            .COM Template . . . . . . .219      JMP . . . . . . . . . . . . .3 
  716.            CONST . . . . . . . . . . .280      JO, JNO . . . . . . . . . . 38 
  717.            CONTINUE. . . . . . . . . .215 
  718.                                                Label . . . . . . . . . . . .3 
  719.            DAA . . . . . . . . . . . .232      LAHF. . . . . . . . . . . .266 
  720.            DAS . . . . . . . . . . . .233      LDS . . . . . . . . . . . .157 
  721.            _DATA . . . . . . . . . . .279      LEA . . . . . . . . . . . .118 
  722.            Data Bus. . . . . . . . . .273      LES . . . . . . . . . . . .157 
  723.            DB, DW, DD, DQ, DT, DF. . . 11      Literals. . . . . . . . . .280 
  724.            DEC . . . . . . . . . . . . 57      LOCK. . . . . . . . . . . .265 
  725.            Definition of Constants . . 13      LODS. . . . . . . . . . . .198 
  726.            DF. . . . . . . . . . . . .191      Long Negation . . . . . . .170 
  727.            DGROUP. . . . . . . . . . .281      LOOP. . . . . . . . . . . . 31 
  728.            DIV . . . . . . . . . . . . 44      LOOPE/LOOPZ . . . . . . . .265 
  729.            Division. . . . . . . . . .xiv      LOOPNE/LOOPNZ . . . . . . .265 
  730.            DO-WHILE. . . . . . . . . .215      .LST File . . . . . . . . . 78 
  731.            
  732.            EBCDIC Numbers. . . . . . .253      Masks . . . . . . . . . . . 52 
  733.            END . . . . . . . . . . . . 97      .MODEL Names. . . . . . . .291 
  734.            ENDS. . . . . . . . . . . . 92      Modular Math. . . . . . . . vi 
  735.            EQU . . . . . . . . . . . .110      MOV . . . . . . . . . . . . 19 
  736.            ESC . . . . . . . . . . . .264      MOVS. . . . . . . . . . . .199 
  737.            Exit Code . . . . . . . . .276      MUL . . . . . . . . . . . . 41 
  738.            EXTRN . . . . . . . . . . . 99      Multiplication. . . . . . xiii 
  739.            EXTRN in Subroutines. . . .142 
  740.  
  741.            ______________________
  742.  
  743.               The PC Assembler Tutor - Copyright (C) 1990 Chuck Nelson
  744.  
  745.  
  746.  
  747.  
  748.                                                                            295
  749.  
  750.            Near Procedures . . . . . .145      Sign Extension. . . . . . . ix 
  751.            NEG . . . . . . . . . . . . 51      Sign Extension. . . . . .xviii 
  752.            Negative Numbers. . . . . . ii      Signed Jumps. . . . . . . . 70 
  753.            NMI . . . . . . . . . . . .181      STACK . . . . . . . . . . .101 
  754.            NOP . . . . . . . . . . . .267      STACK . . . . . . . . . . .280 
  755.            NOT . . . . . . . . . . . . 51      Standardized 
  756.            NOT . . . . . . . . . . .xxiii         Segment Directives . . .288 
  757.            Numbers In Memory . . . .xxvii         Segment Names. . . . . .287 
  758.                                                   Segments . . . . . . . .277 
  759.            OF. . . . . . . . . . . . . 32      STI . . . . . . . . . . . .181 
  760.            OFFSET. . . . . . . . . . .118      STOS. . . . . . . . . . . .196 
  761.            OR. . . . . . . . . . . . . 50      SUB . . . . . . . . . . . . 37 
  762.            OR. . . . . . . . . . . . xxii      Subroutines . . . . . . . . 96 
  763.            OUT . . . . . . . . . . . .186      Subtraction . . . . . . . . .v 
  764.            Overflow. . . . . . . . . .xii      SWITCH. . . . . . . . . . .217 
  765.            
  766.            Packed BCD. . . . . . . . .230      Ten's Complement. . . . . .iii 
  767.            Packing BCDs. . . . . . . .246      TEST. . . . . . . . . . . . 49 
  768.            Parity. . . . . . . . . . .186      The Stack . . . . . . . . .148 
  769.            Passing Data. . . . . . . .144      Towers of Hanoi . . . . . .162 
  770.            Phase Errors. . . . . . . .221      Translation Table . . . . .253 
  771.            POP . . . . . . . . . . . . 34      Two's Complement. . . . . xvii 
  772.            POPREGS . . . . . . . . . .154      Types of Returns. . . . . .153 
  773.            PSP . . . . . . . . . . . .220 
  774.            PUBLIC (Data) . . . . . . .142      Unpacked BCD. . . . . . . .229 
  775.            PUBLIC (SEGMENTS) . . . . . 85      Unpacking BCDs. . . . . . .245 
  776.            PUSH. . . . . . . . . . . . 33      Unsigned Division . . . . .130 
  777.            PUSHREGS. . . . . . . . . .154      Unsigned Jumps. . . . . . . 70 
  778.            PUSHREGS.MAC. . . . . . . .137      Unsigned Multiplication . .129 
  779.            
  780.            RCL, RCR. . . . . . . . . . 61      WAIT. . . . . . . . . . . .264 
  781.            Registers . . . . . . . . . 16      WHILE . . . . . . . . . . .214 
  782.            REP . . . . . . . . . . . .195 
  783.            REP and Overrides . . . . .209      XCHG. . . . . . . . . . . .264 
  784.            REPE/REPZ . . . . . . . . .195      XLAT. . . . . . . . . . . .253 
  785.            REPNE/REPNZ . . . . . . . .195      XOR . . . . . . . . . . . . 50 
  786.            RET . . . . . . . . . . . . 98      XOR . . . . . . . . . . . xxii 
  787.            ROL, ROR. . . . . . . . . . 60 
  788.                                                ZF. . . . . . . . . . . . . 32 
  789.            SAHF. . . . . . . . . . . .267          
  790.            SAL . . . . . . . . . . . . 56 
  791.            SAR . . . . . . . . . . . . 59 
  792.            SBB . . . . . . . . . . . .126 
  793.            SCAS. . . . . . . . . . . .191 
  794.            SEG (operator). . . . . . .118 
  795.            SEGMENT . . . . . . . . . . 84 
  796.            Segment Overrides . . . . . 93 
  797.            Segment Overrides . . . . .207 
  798.            Segmentation. . . . . . . .xxv 
  799.            SF. . . . . . . . . . . . . 32 
  800.            SHL . . . . . . . . . . . . 56 
  801.            Show_reg Codes. . . . . . . 29 
  802.            Show_regs . . . . . . . . . 17 
  803.            SHR . . . . . . . . . . . . 58 
  804.  
  805.